<?php
include_once("../Dao/db.php");
Class AccountConfig
{
	var $budget_email = "";
	
	var $budget;
	
	var $budget_limit;
	
	var $errorMessage;
	
	
	function mytask()
	{
		if ($_POST["save"] == "保存")
		{
			$this->budget_email = $_POST["budget_email"];
			$this->budget = $_POST["budget"];
			$this->budget_limit = $_POST["budget_limit"];
			$this->doUpdate();
		}
		else 
		{
			
			$this->doInit();
		}
	}
	
	function doInit()
	{
		session_start();
		$sql = "select budgetEmail,budget,budgetLimit from account  ";
		$sql = $sql." where  memberId=".$_SESSION["memberId"]." ";
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			$data = mysql_fetch_row($result);	
			$this->budget_email = $data[0];
			$this->budget = $data[1];
			$this->budget_limit = $data[2];		
		}
	}
	
	function doUpdate()
	{
		session_start();
		if( $_POST["budget_email"] == "") 
		{
			$budgetEmail = "null";
		}else{
			$budgetEmail = "'{$_POST["budget_email"]}'";
		}
		
		if( $_POST["budget"] == "")
		{
			$budget = "null";
		}else{
			$budget = $_POST["budget"];
		}
		
		if( $_POST["budget_limit"] == "")
		{
			$budgetLimit = "null";
		}else{
			$budgetLimit = $_POST["budget_limit"];
		}
		
		$sql = "update account ";
		$sql = $sql." set budgetEmail=".$budgetEmail.",budget=".$budget.",budgetLimit=".$budgetLimit ;
		$sql = $sql." where memberId=".$_SESSION["memberId"];	
		
		$result = mysql_query($sql);		
		if ($result != "1")
		{
			$this->errorMessage = "更新できません。";
			return;
		}
		
	}
}